package com.kelvem.saas.workbanch.security.shiro.encoder;

import org.mindrot.jbcrypt.BCrypt;
import org.springframework.stereotype.Service;

@Service
public class BCryptPasswordEncoder implements PasswordEncoder {

    public String hash(String password) {
        String salt = BCrypt.gensalt(10); // 生成一个盐值，10 表示迭代次数为 2^10

        // 生成 BCrypt 哈希
        String hashedPassword = BCrypt.hashpw(password, salt);
        return hashedPassword;
    }

    public boolean check(String plaintext, String hashed) {
        boolean flag = BCrypt.checkpw(plaintext, hashed);
        return flag;
    }

}
